package com.mydiary.ui;

import com.mydiary.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.TabHost;

public class PortalActivity extends TabActivity implements OnClickListener {

	private TabHost mTabHost;
	private Intent mListIntent,mFootIntent,mMemoIntent,mSettingIntent;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE); 
		setContentView(R.layout.portal_layout);
		this.mListIntent=new Intent(this, ListActivity.class);
		this.mFootIntent=new Intent(this,FootActivity.class);
		this.mMemoIntent=new Intent(this,MemoActivity.class);
		this.mSettingIntent=new Intent(this,SettingActivity.class);
		((RadioButton)findViewById(R.id.rd_list)).setOnClickListener(this);
		((RadioButton)findViewById(R.id.rd_foot)).setOnClickListener(this);
		((RadioButton)findViewById(R.id.rd_memo)).setOnClickListener(this);
		((RadioButton)findViewById(R.id.rd_new)).setOnClickListener(this);
		((RadioButton)findViewById(R.id.rd_setting)).setOnClickListener(this);
		setupIntent();
		((RadioButton)findViewById(R.id.rd_list)).setChecked(true);
	}

	
	private void setupIntent() { 
        this.mTabHost = getTabHost(); 
        TabHost localTabHost = this.mTabHost; 
 
        localTabHost.addTab(buildTabSpec("LIST_TAB", this.mListIntent)); 
 
        localTabHost.addTab(buildTabSpec("FOOT_TAB", this.mFootIntent)); 
 
        localTabHost.addTab(buildTabSpec("MEMO_TAB", this.mMemoIntent)); 
 
        localTabHost.addTab(buildTabSpec("SETTING_TAB", this.mSettingIntent)); 
 
    } 
     
    private TabHost.TabSpec buildTabSpec(String tag, /*int resLabel, int resIcon,*/ 
            final Intent intent) { 
        return this.mTabHost.newTabSpec(tag).setIndicator(null/*getString(R.string.app_name)*/, 
                /*getResources().getDrawable(R.drawable.btn_style_two_focused)*/null).setContent(intent); 
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.rd_list:
			mTabHost.setCurrentTabByTag("LIST_TAB");
			break;
		case R.id.rd_foot:
			mTabHost.setCurrentTabByTag("FOOT_TAB");
			break;
		case R.id.rd_memo:
			mTabHost.setCurrentTabByTag("MEMO_TAB");
			break;
		case R.id.rd_setting:
			mTabHost.setCurrentTabByTag("SETTING_TAB");
			break;
		case R.id.rd_new:
			break;
		}
	}


	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode==KeyEvent.KEYCODE_BACK)
		{
			finish();
		}
		return super.onKeyDown(keyCode, event);
	} 

}
